Permalink
Browse files

Adaptation to Confluence4

  • Loading branch information...
1 parent 84abe34 commit eb729533b371b4296999994a0217855454d8941d @adutra committed Mar 7, 2012
Showing with 77 additions and 313 deletions.
  1. +0 −12 pom.xml
  2. +1 −2 src/main/java/fr/xebia/confluence2wordpress/core/converter/DefaultConverter.java
  3. 0 ...main/java/fr/xebia/confluence2wordpress/core/converter/postprocessors/CodeMacroPostprocessor.java
  4. 0 src/main/java/fr/xebia/confluence2wordpress/core/converter/preprocessors/MoreMacroPreprocessor.java
  5. 0 src/main/java/fr/xebia/confluence2wordpress/core/converter/visitors/AnchorProcessor.java
  6. 0 src/main/java/fr/xebia/confluence2wordpress/core/converter/visitors/EmptyParagraphStripper.java
  7. 0 src/main/java/fr/xebia/confluence2wordpress/core/converter/visitors/EmptySpanStripper.java
  8. 0 src/main/java/fr/xebia/confluence2wordpress/core/converter/visitors/TagStripperBase.java
  9. +5 −2 src/main/java/fr/xebia/confluence2wordpress/core/metadata/DefaultMetadataManager.java
  10. 0 src/main/java/fr/xebia/confluence2wordpress/macro/SyncInfoMacro.java
  11. +0 −49 src/main/java/fr/xebia/confluence2wordpress/util/ClassUtils.java
  12. +0 −56 src/main/java/fr/xebia/confluence2wordpress/util/EscapeUtils.java
  13. +0 −48 src/main/java/fr/xebia/confluence2wordpress/util/HtmlUtils.java
  14. 0 src/main/java/fr/xebia/confluence2wordpress/util/UrlUtils.java
  15. 0 src/main/java/fr/xebia/confluence2wordpress/util/XPathUtils.java
  16. +0 −36 src/main/java/org/htmlcleaner/WhitespaceTolerantTagInfo.java
  17. +0 −40 src/main/java/org/htmlcleaner/WhitespaceTolerantTagInfoProvider.java
  18. 0 src/main/resources/vm/sync-info.vm
  19. +5 −2 src/test/java/fr/xebia/confluence2wordpress/core/metadata/MetadataManagerTest.java
  20. 0 src/test/java/fr/xebia/confluence2wordpress/util/UrlUtilsTest.java
  21. 0 src/test/java/fr/xebia/confluence2wordpress/util/XPathUtilsTest.java
  22. +57 −57 src/test/resources/metadata.json
  23. +9 −9 src/test/resources/test.txt
View
@@ -94,18 +94,6 @@
</exclusions>
</dependency>
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>2.0</version>
- </dependency>
-
- <dependency>
- <groupId>org.joda</groupId>
- <artifactId>joda-convert</artifactId>
- <version>1.1</version>
- </dependency>
-
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
@@ -34,7 +34,6 @@
import org.htmlcleaner.TagNode;
import org.htmlcleaner.TagNodeVisitor;
import org.htmlcleaner.TagTransformation;
-import org.htmlcleaner.WhitespaceTolerantTagInfoProvider;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
@@ -152,7 +151,7 @@ private void handleConversionErrors(String view) throws ConversionException {
private HtmlCleaner getHtmlCleaner(ConverterOptions options) {
//HtmlCleaner is NOT thread-safe
CleanerProperties cleanerProps = getCleanerProperties(options);
- HtmlCleaner cleaner = new HtmlCleaner(new WhitespaceTolerantTagInfoProvider(), cleanerProps);
+ HtmlCleaner cleaner = new HtmlCleaner(cleanerProps);
CleanerTransformations transformations = getCleanerTransformations(options);
cleaner.setTransformations(transformations);
return cleaner;
@@ -37,6 +37,7 @@
import com.atlassian.confluence.xhtml.api.MacroDefinitionUpdater;
import com.atlassian.confluence.xhtml.api.XhtmlContent;
+import fr.xebia.confluence2wordpress.util.CodecUtils;
import fr.xebia.confluence2wordpress.wp.WordpressCategory;
import fr.xebia.confluence2wordpress.wp.WordpressUser;
@@ -159,7 +160,8 @@ public Metadata createMetadata(
public Metadata unmarshalMetadata(String macroBody) throws MetadataException {
try {
- return mapper.readValue(macroBody, Metadata.class);
+ String expanded = CodecUtils.decodeAndExpand(macroBody);
+ return mapper.readValue(expanded, Metadata.class);
} catch (JsonParseException e) {
throw new MetadataException("Cannot unmarshal macro body: " + macroBody, e);
} catch (JsonMappingException e) {
@@ -171,7 +173,8 @@ public Metadata unmarshalMetadata(String macroBody) throws MetadataException {
public String marshalMetadata(Metadata metadata) throws MetadataException {
try {
- return mapper.writeValueAsString(metadata);
+ String json = mapper.writeValueAsString(metadata);
+ return CodecUtils.compressAndEncode(json);
} catch (JsonParseException e) {
throw new MetadataException("Cannot marshal metadata: " + metadata, e);
} catch (JsonMappingException e) {
@@ -1,49 +0,0 @@
-/**
- * Copyright 2011 Alexandre Dutra
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package fr.xebia.confluence2wordpress.util;
-
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-
-
-public final class ClassUtils {
-
- private static final Map<Class<?>, Class<?>> WRAPPERS = Maps.newConcurrentMap();
-
- static {
- WRAPPERS.put(byte.class, Byte.class);
- WRAPPERS.put(short.class, Short.class);
- WRAPPERS.put(char.class, Character.class);
- WRAPPERS.put(int.class, Integer.class);
- WRAPPERS.put(long.class, Long.class);
- WRAPPERS.put(float.class, Float.class);
- WRAPPERS.put(double.class, Double.class);
- WRAPPERS.put(boolean.class, Boolean.class);
- }
-
- public static Class<?> getPrimitiveWrapperType(Class<?> primitiveType){
- if(! primitiveType.isPrimitive()){
- throw new IllegalArgumentException("Not a primitive type: " + primitiveType);
- }
- return WRAPPERS.get(primitiveType);
- }
-
- private ClassUtils() {
- }
-
-}
@@ -1,56 +0,0 @@
-/**
- * Copyright 2011 Alexandre Dutra
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package fr.xebia.confluence2wordpress.util;
-
-
-
-public final class EscapeUtils {
-
- public static String escape(String s) {
- if(s == null || "".equals(s)){
- return "";
- }
- if(shouldEscape(s)){
- StringBuilder sb = new StringBuilder();
- sb.append("\"");
- sb.append(s.replace("\"","\"\""));
- sb.append("\"");
- return sb.toString();
- }
- return s;
- }
-
- public static String unescape(String s) {
- if(s == null || "".equals(s)){
- return null;
- }
- if(s.startsWith("\"") && s.endsWith("\"")){
- String unescaped = s.substring(1, s.length() - 1);
- if(shouldEscape(unescaped)){
- return unescaped.replace("\"\"", "\"");
- }
- }
- return s;
- }
-
- public static boolean shouldEscape(String s) {
- return s.contains(",") || s.contains("=") || s.contains("\"");
- }
-
- private EscapeUtils() {
- }
-
-}
@@ -1,48 +0,0 @@
-/**
- * Copyright 2011 Alexandre Dutra
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- *
- */
-package fr.xebia.confluence2wordpress.util;
-
-import org.apache.commons.lang.StringUtils;
-
-/**
- * @author Alexandre Dutra
- *
- */
-public class HtmlUtils{
-
- public static final String CDATA_START = "<![CDATA[";
-
- public static final String CDATA_END = "]]>";
-
- /**
- * @see "http://www.w3.org/TR/html401/struct/text.html#h-9.1"
- * ASCII space (&#x0020;)
- * ASCII tab (&#x0009;)
- * carriage return (&#x000D;)
- * line feed (&#x000A;)
- * ASCII form feed (&#x000C;)
- * Zero-width space (&#x200B;)
- */
- private static final String WHITESPACE = " \t\r\n\u000C\u200B";
-
- public static boolean isHtmlWhitespace(String text){
- return StringUtils.containsOnly(text, WHITESPACE);
- }
-
-}
No changes.
No changes.
@@ -1,36 +0,0 @@
-/**
- * Copyright 2011 Alexandre Dutra
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.htmlcleaner;
-
-import fr.xebia.confluence2wordpress.util.HtmlUtils;
-
-public class WhitespaceTolerantTagInfo extends TagInfo {
-
- public WhitespaceTolerantTagInfo(String name, int contentType, int belongsTo, boolean deprecated, boolean unique, boolean ignorePermitted) {
- super(name, contentType, belongsTo, deprecated, unique, ignorePermitted);
- }
-
- @Override
- boolean allowsItem(BaseToken token) {
- if(token instanceof ContentNode) {
- if(HtmlUtils.isHtmlWhitespace(((ContentNode) token).getContent().toString())){
- return true;
- }
- }
- return super.allowsItem(token);
- }
-
-}
@@ -1,40 +0,0 @@
-/**
- * Copyright 2011 Alexandre Dutra
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.htmlcleaner;
-
-
-public class WhitespaceTolerantTagInfoProvider extends DefaultTagProvider implements ITagInfoProvider {
-
- /**
- *
- */
- private static final long serialVersionUID = 6349860503307965029L;
-
- @Override
- public TagInfo put(String key, TagInfo value) {
- WhitespaceTolerantTagInfo info = new WhitespaceTolerantTagInfo(value.getName(), value.getContentType(), value.getBelongsTo(), value.isDeprecated(), value.isUnique(), value.isIgnorePermitted());
- info.setChildTags(value.getChildTags());
- info.setContinueAfterTags(value.getContinueAfterTags());
- info.setCopyTags(value.getCopyTags());
- info.setFatalTag(value.getFatalTag());
- info.setHigherTags(value.getHigherTags());
- info.setMustCloseTags(value.getMustCloseTags());
- info.setPermittedTags(value.getPermittedTags());
- info.setRequiredParent(value.getRequiredParent());
- return super.put(key, info);
- }
-
-}
View
No changes.
@@ -33,6 +33,8 @@
import com.atlassian.confluence.xhtml.api.XhtmlContent;
import com.google.common.collect.Maps;
+import fr.xebia.confluence2wordpress.util.CodecUtils;
+
@RunWith(MockitoJUnitRunner.class)
public class MetadataManagerTest {
@@ -49,7 +51,7 @@ public void prepare() throws IOException {
@Test
public void testUnmarshalMetadata() throws Exception {
MetadataManager m = new DefaultMetadataManager(xhtmlUtils);
- Metadata metadata = m.unmarshalMetadata(json);
+ Metadata metadata = m.unmarshalMetadata(CodecUtils.compressAndEncode(json));
assertEquals(new Date(1330693920000L), metadata.getDateCreated());
assertEquals("7e0cb48cb807c098d34206091c862d449652d1d6581e82b20e29f5e223f768fd", metadata.getDigest());
assertEquals(true, metadata.isDraft());
@@ -63,7 +65,7 @@ public void testUnmarshalMetadata() throws Exception {
}
@Test
- public void testMarshallMetadata() throws MetadataException {
+ public void testMarshallMetadata() throws Exception {
Metadata metadata = new Metadata();
metadata.setIncludeTOC(true);
metadata.setPostId(43);
@@ -76,6 +78,7 @@ public void testMarshallMetadata() throws MetadataException {
metadata.setPermalink("http://foo.com/bar");
MetadataManager m = new DefaultMetadataManager(xhtmlUtils);
String json = m.marshalMetadata(metadata);
+ json = CodecUtils.decodeAndExpand(json);
assertTrue(json.contains("\"tagNames\":[\"lorem\",\"ipsum\"]"));
assertTrue(json.contains("\"tagAttributes\":{\"img\":\"style=\\\"foo\\\" class='bar'\",\"a\":\"\",\"p\":\"alt=\\\"foo\\\"\"}"));
assertTrue(json.contains("\"permalink\":\"http://foo.com/bar\""));
Oops, something went wrong.

0 comments on commit eb72953

Please sign in to comment.