Drupal: když chybí předmět, doplníme ho z prostého textu (ne z XHTML).
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun Oct 23 23:37:39 2011 +0200 (2011-10-23)
changeset 106dc04a3c2c557
parent 105 d566d08c20d6
child 107 b723308e1359
Drupal: když chybí předmět, doplníme ho z prostého textu (ne z XHTML).
src/org/sonews/storage/DrupalMessage.java
src/org/sonews/storage/impl/DrupalDatabase.java
     1.1 --- a/src/org/sonews/storage/DrupalMessage.java	Fri Oct 21 18:21:30 2011 +0200
     1.2 +++ b/src/org/sonews/storage/DrupalMessage.java	Sun Oct 23 23:37:39 2011 +0200
     1.3 @@ -135,7 +135,7 @@
     1.4  
     1.5  			/** Plain text part */
     1.6  			MimeBodyPart textPart = new MimeBodyPart();
     1.7 -			String plainText = readPlainText(rs, xhtmlText);
     1.8 +			String plainText = formatedToPlainText(xhtmlText);
     1.9  			textPart.setText(plainText);
    1.10  			//addHeader("Lines", String.valueOf(plainText.split("\n").length));
    1.11  
    1.12 @@ -185,7 +185,11 @@
    1.13  		return new ByteArrayInputStream(message);
    1.14  	}
    1.15  
    1.16 -	private String readPlainText(ResultSet rs, String xhtmlText) {
    1.17 +	/**
    1.18 +	 * @param xhtmlText well-formed XHTML
    1.19 +	 * @return plain text representation of this formated text
    1.20 +	 */
    1.21 +	private String formatedToPlainText(String xhtmlText) {
    1.22  		try {
    1.23  			Transformer textTransformer = transformerFactory.newTransformer(new StreamSource(Resource.getAsStream("helpers/mimeTextPart.xsl")));
    1.24  
    1.25 @@ -199,7 +203,7 @@
    1.26  			 * TODO: lepší ošetření chyby
    1.27  			 */
    1.28  			log.log(Level.WARNING, "Error while transforming article to plain text", e);
    1.29 -			return makeSimpleXHTML("Při transformaci příspěvku bohužel došlo k chybě.");
    1.30 +			return "Při transformaci příspěvku bohužel došlo k chybě.";
    1.31  		}
    1.32  	}
    1.33  
    1.34 @@ -499,4 +503,11 @@
    1.35  			throw new StorageBackendException(e);
    1.36  		}
    1.37  	}
    1.38 +	
    1.39 +	public String getBodyPlainText() throws StorageBackendException {
    1.40 +		/**
    1.41 +		 * TODO: netransformovat XHTML 2x
    1.42 +		 */
    1.43 +		return formatedToPlainText(makeSimpleXHTML(getBodyXhtmlFragment()));
    1.44 +	}
    1.45  }
     2.1 --- a/src/org/sonews/storage/impl/DrupalDatabase.java	Fri Oct 21 18:21:30 2011 +0200
     2.2 +++ b/src/org/sonews/storage/impl/DrupalDatabase.java	Sun Oct 23 23:37:39 2011 +0200
     2.3 @@ -419,7 +419,11 @@
     2.4  					String text = m.getBodyXhtmlFragment();
     2.5  
     2.6  					if (subject == null || subject.length() < 1) {
     2.7 -						subject = text.substring(0, Math.min(10, text.length()));
     2.8 +						String plainText = m.getBodyPlainText();
     2.9 +						subject = plainText.substring(0, Math.min(32, plainText.length()));
    2.10 +						if (subject.length() < plainText.length()) {
    2.11 +							subject = subject + "…";
    2.12 +						}
    2.13  					}
    2.14  
    2.15  					insertArticle(article.getAuthenticatedUser(), subject, text, parentID, groupID);